<template>
  <div class="wrapper">
    <div v-if="$store.state.showTip" class="show-tip">{{showContent}}</div>
    <div class="tabel-div">
      <table class="tabel-class">
        <thead>
        <tr>
          <th>文章标题</th>
          <th>来源</th>
          <th>作者</th>
          <th>发布时间</th>
          <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <tr v-for="re in $store.state.records">
          <td>《{{re.hotspotTitle}}》</td>
          <td>{{re.hotspotSource}}</td>
          <td>{{re.hotspotAuthor}}</td>
          <td>{{getDateByMoment(re.itemupdateat)}}


          </td>
          <!--<td>修改 提交 删除</td>-->
          <td class="op-a">
            <a href="javascript:void(0)" v-if="re.dataStatus==8">查看</a>
            <a href="javascript:void(0)" v-if="re.dataStatus==7">待审核</a>
            <a href="javascript:void(0)" v-if="re.dataStatus==6"  @click="updateph(re)">修改</a>
            <a href="javascript:void(0)" v-if="re.dataStatus==6"  @click="submitph(re)" >提交</a>
            <a href="javascript:void(0)" v-if="re.dataStatus==6" @click="deleteph(re.itemcode)">删除</a>

          </td>
        </tr>
        </tbody>
      </table>
    </div>

    <div class="">
      <div class="container large arowMain">
        <div class="pagination arow6">
          <ul>
            <li v-on:click="topPage()"><a href="javascript:void(0)">首页</a></li>
            <li v-on:click="lastPage()"><a href="javascript:void(0)"><</a></li>
            <li v-for="num in indexs" :class="{active:$store.state.current_page==num}" @click="jumpPage(num)">
              <a href="javascript:void(0)">{{num}}</a>
            </li>
            <li v-on:click="nextPage()"><a href="javascript:void(0)"> > </a></li>
            <li v-on:click="bottomPage()"><a href="javascript:void(0)">尾页</a></li>
            <!--<li class="active"><a href="javascript:void(0)"></a></li>-->
          </ul>
        </div>
        <div class="arow03">
          <input type="text" id="select-state" v-model="$store.state.selectStateValue" class="input-class"
                 placeholder="6条/页"
                 readonly
                 @blur="ul_hide" @focus="ul_show"/>
          <ul class="showUlleft" id="listsShowUlleft" v-if="$store.state.show_ul" v-on:click="selectState">
            <li><a href="javascript:void(0)">6条/页</a></li>
            <li><a href="javascript:void(0)">10条/页</a></li>
            <li><a href="javascript:void(0)">20条/页</a></li>
            <li><a href="javascript:void(0)">30条/页</a></li>
            <li><a href="javascript:void(0)">50条/页</a></li>
            <li><a href="javascript:void(0)">70条/页</a></li>
            <li><a href="javascript:void(0)">100条/页</a></li>
          </ul>
        </div>
        <div class="arow03">
          <label>跳转至</label>
        </div>
        <div class="arow03">
          <input type="text" v-model="$store.state.jumpTo" @change="jumpAllPage()" class="input-class" placeholder="0"/>
        </div>
        <div class="arow03 wei-page">
          <label>页</label>
        </div>


      </div>
    </div>
  </div>
</template>

<script>

  import moment from 'moment'
  import axios from 'axios'

  export default {
    name: "HealthPreservationBody",
    data() {
      return {
        showContent: ""
        // this.$store.state.current_page: 1, //当前页
        // pages: 50, //总页数
        // changePage: '',//跳转页
        // pageSum: 6,//每页大小
        // nowIndex: 0,
        // show_ul: false,
        // selectStateValue: '',
        // jumpTo: 1,
        // records: []


      }
    },
    created() {
      this.$store.commit('setRecordsByAXIOS');


    },
    computed: {
      show: function () {


        return this.$store.state.pages && this.$store.state.pages != 1
      },
      efont: function () {
        if (this.$store.state.pages <= 7) return false;
        return this.$store.state.current_page > 5
      },
      indexs: function () {

        var left = 1,
          right = this.$store.state.pages,
          ar = [];
        if (this.$store.state.pages >= 7) {
          if (this.$store.state.current_page > 5 && this.$store.state.current_page < this.$store.state.pages - 4) {
            left = Number(this.$store.state.current_page) - 3;
            right = Number(this.$store.state.current_page) + 3;
          } else {
            if (this.$store.state.current_page <= 5) {
              left = 1;
              right = 7;
            } else {
              right = this.$store.state.pages;

              left = this.$store.state.pages - 6;
            }
          }
        }
        while (left <= right) {
          ar.push(left);
          left++;
        }


        return ar;
      },


    },
    methods: {
      jumpPage: function (id) {

        this.$store.commit("setCurrent_page", id);
        // this.$store.state.current_page = id;
        this.$store.commit('setRecordsByAXIOS');
      },
      jumpAllPage: function () {
        if (this.$store.state.jumpTo > this.$store.state.pages || this.$store.state.jumpTo < 0) {

        } else {
          // this.$store.state.current_page = this.$store.state.jumpTo;

          this.$store.commit("setCurrent_page", this.$store.state.jumpTo);

          this.$store.commit('setRecordsByAXIOS');
        }
      },

      // changePageClick: function (e) {
      //   console.log("#" + e.target)
      // },
      nextPage: function () {
        if (this.$store.state.current_page < this.$store.state.pages) {
          let a = this.$store.state.current_page;

          this.$store.commit("setCurrent_page", ++a);


          this.$store.commit('setRecordsByAXIOS');
        }

      },
      lastPage: function () {
        if (this.$store.state.current_page > 1) {
          // this.$store.state.current_page--;

          let a = this.$store.state.current_page;

          this.$store.commit("setCurrent_page", --a);

          this.$store.commit('setRecordsByAXIOS');
        }

      },
      topPage: function () {
        // this.$store.state.current_page = 1;


        this.$store.commit("setCurrent_page", 1);

        this.$store.commit('setRecordsByAXIOS');
      },
      bottomPage: function () {
        // this.$store.state.current_page = this.$store.state.pages;


        this.$store.commit("setCurrent_page", this.$store.state.pages);

        this.$store.commit('setRecordsByAXIOS');
      },
      ul_hide: function () {
        setTimeout(() => {

          this.$store.commit("setShow_ul");

        }, 200);
      },
      ul_show: function () {

        this.$store.commit("setShow_ul");
      },
      selectState: function (e) {
        this.$store.commit('setSelectStateValue', e.target.text);
        let a = e.target.text;
        a = a.substring(0, a.length - 3)
        // this.pageSum = a;
        this.$store.commit("setPageSum", a);

        // this.$store.state.current_page = 1;
        this.$store.commit("setCurrent_page", 1);

        this.$store.commit('setRecordsByAXIOS');
      },
      getDateByMoment: function (date) {

        return moment(date).format("YYYY-MM-DD hh:mm:ss")
      },

      deleteph: function (itemcode) {

        axios.get(`http://localhost:8071/deleteTbNatmehaHotspotHealthPreservation?itemcode=`+itemcode)
          .then(res => {
            if (res.data.code == 200) {
              this.$store.commit('setRecordsByAXIOS');
            }
            this.showContent = res.data.msg;
            this.$store.commit("setShowTip")
          })
      },
      updateph:function (item) {
        // console.log("@@@@@@@@@@@@@@@@",item);
        this.$store.commit('setRecord',item);
        this.$router.push({path:"/AddHealthPreservation"})

      },
      submitph:function (item) {
        this.$store.commit('setRecord',item);
        let  v1=item.itemcode;
        let v2=7;
        axios.get('http://localhost:8071/updateTbNatmehaHotspotHealthPreservationStatus?itemcode=' + v1+ '&status=' + v2 ).then((res) => {
          if(res.data.code==200){
            this.$store.commit('setRecordsByAXIOS');
          }
          this.showContent = res.data.msg;
          this.$store.commit("setShowTip")


        });

      }


//       initGetData() {
//         axios.get('http://localhost:8071/getHealthPreservation?current=' + this.$store.state.current_page + '&limit=' + this.$store.state.pageSum).then((res) => {
// console.log("废弃")
//           this.$store.commit('setPages',res.data.pages);
//           // this.pages = res.data.pages;
//           // this.records = res.data.records;
//           // store.state.records=res.data.records;
//           this.$store.commit('setRecords',res.data.records);
//           // this.seller = res.data.seller
//           // this.$nextTick(() => {
//           //   this.sellerScroll = new BScroll(this.$refs.sellerWrapper, {
//           //     click: true
//           //   })
//           //   this._initPicScroll()
//           // })
//         })
//       },


    }


  }
</script>

<style scoped>
  .tabel-div {
    width: 100%;
  }

  * {
    margin: 0;
    padding: 0;
  }

  .tabel-class {
    width: 100%;
    /*border: 0;*/
    border-collapse: collapse;
  }

  .tabel-class > thead {
    background-color: #775637;
    color: white;

  }

  .tabel-class > thead > tr > th {
    padding-top: 10px;
    padding-bottom: 10px;
    font-size: 13px;
    border: 0;
  }

  .tabel-class td {
    padding: 25px 0 20px 0;
    color: #775637;
  }

  .tabel-class > tbody > tr > td:first-child {
    max-width: 220px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .wrapper {
    width: 80%;
    margin: auto;
    padding: 0;
  }

  .showUlleft {
    background-color: white;
    /*text-indent: px;*/
    list-style: none;
    border: .3px gainsboro solid;
    width: 70px;
    position: relative;
  }

  .showUlleft > li:hover {
    background-color: #1E90FF;
  }

  .showUlleft > li {
    display: block;
    width: 100%;

  }

  .showUlleft > li > a {
    line-height: 1.3;
    font-size: 15px;
    display: block;

    text-decoration: none;
    color: #333333;
    text-align: left;
    margin-left: 10px;
    padding-top: 5px;
    padding-bottom: 5px;
  }

  .arowMain {
    display: flex;
  }

  .arow1 {
    flex: 1;
  }

  .arow03 {
    flex: 0.5;
    line-height: 40px;
  }

  .wei-page {
    margin-left: 5px;
    text-align: left;
  }

  .arow6 {
    flex: 6;
    text-align: right;
  }

  .input-class {
    width: 60px;
    height: 38px;
    line-height: 1.3;
    border-width: 1px;
    border-style: solid;
    background-color: #fff;
    color: rgba(0, 0, 0, .85);
    border-radius: 2px;
    border-color: #eee;
    outline: none;
    display: block;
    padding-left: 10px;

  }

  /*///////////////*/
  .container {
    background: #fdfdfd;
    padding: 1rem;
    margin: 3rem auto;
    border-radius: 0.2rem;
    counter-reset: pagination;
    text-align: center;
  }

  .container:after {
    clear: both;
    content: "";
    display: table;
  }

  /*.container ul {*/
  /*width: 100%;*/
  /*}*/

  /*.large {*/
  /*width: 45rem;*/
  /*}*/
  .pagination {
    margin-right: 10px;
  }

  .pagination ul, li {
    list-style: none;
    display: inline;
    padding-left: 0px;
  }

  .pagination li {
    counter-increment: pagination;
  }

  .pagination li:hover a {
    color: #fdfdfd;
    background-color: #775637;
    border: solid 1px #775637;
  }

  .pagination li.active a {
    color: #fdfdfd;
    background-color: #775637;
    border: solid 1px #775637;
  }

  /*.pagination li:first-child a:after {*/
  /*content: "<";*/
  /*}*/

  /*.pagination li:nth-child(2) {*/
  /*counter-reset: pagination;*/
  /*}*/

  /*.pagination li:last-child a:after {*/
  /*content: ">";*/
  /*}*/

  .pagination li a {
    border: solid 1px #d6d6d6;
    border-radius: 0.2rem;
    color: #7d7d7d;
    text-decoration: none;
    text-transform: uppercase;
    display: inline-block;
    text-align: center;
    padding: 0.5rem 0.9rem;
  }

  .pagination li a:after {
    /*content: " " counter(pagination) " ";*/
    /*content: counter(pagination);*/
  }

  .large li a {
    /*display: none;*/
  }

  /*.large li:first-child a {*/
  /*display: inline-block;*/
  /*}*/

  /*.large li:first-child a:after {*/
  /*content: "<";*/
  /*}*/

  /*.large li:nth-child(2) a {*/
  /*display: inline-block;*/
  /*}*/

  /*.large li:nth-child(3) a {*/
  /*display: inline-block;*/
  /*}*/

  /*.large li:nth-child(4) a {*/
  /*display: inline-block;*/
  /*}*/

  /*.large li:nth-child(5) a {*/
  /*display: inline-block;*/
  /*}*/

  /*.large li:nth-child(6) a {*/
  /*display: inline-block;*/
  /*}*/

  /*.large li:nth-child(7) a {*/
  /*display: inline-block;*/
  /*}*/

  /*.large li:nth-child(8) a {*/
  /*display: inline-block;*/
  /*}*/

  /*.large li:last-child a {*/
  /*display: inline-block;*/
  /*}*/

  /*.large li:last-child a:after {*/
  /*content: ">";*/
  /*}*/

  /*.large li:nth-last-child(2) a {*/
  /*display: inline-block;*/
  /*}*/

  /*.large li:nth-last-child(3) {*/
  /*display: inline-block;*/
  /*}*/

  /*.large li:nth-last-child(3):after {*/
  /*padding: 0 1rem;*/
  /*content: "...";*/
  /*}*/
  .op-a > a {
    text-decoration: none;
    /*list-style: none;*/
  }

  .show-tip {
    position: fixed;
    top: 50px;
    left: 50%;
    z-index: 9999;
    height: 35px;
    padding: 0 20px;
    line-height: 35px;
    background-color: rgba(65, 65, 65, 0.7);
    color: white;

  }
</style>
